package com.lin.cms.service.impl;

import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lin.cms.util.Paging;
import com.lin.cms.criteria.ChannelExtCriteria;
import com.lin.cms.domain.ChannelExt;
import com.lin.cms.service.ChannelExtService;
import com.lin.cms.dao.ChannelExtMapper;

@Service
public class ChannelExtServiceImpl implements ChannelExtService{
	
	public ChannelExt selectByPrimaryKey(Integer channelId){
		return channelExtMapper.selectByPrimaryKey(channelId);
	}
	
	public List<ChannelExt> selectByCriteria(ChannelExtCriteria criteria){
		return channelExtMapper.selectByCriteria(criteria);
	}
	
	public int deleteByPrimaryKey(Integer channelId){
		int actualRowsAffected = 0;
		
		ChannelExt _oldChannelExt = channelExtMapper.selectByPrimaryKey(channelId);
		
		if (_oldChannelExt != null) {
			actualRowsAffected = channelExtMapper.deleteByPrimaryKey(channelId);
		}
		
		return actualRowsAffected;
	}
	
	public int deleteByCriteria(ChannelExtCriteria criteria){
		int actualRowsAffected = 0;
		
		List<ChannelExt> _oldChannelExt = channelExtMapper.selectByCriteria(criteria);
		
		if (_oldChannelExt.size() != 0) {
			actualRowsAffected = channelExtMapper.deleteByCriteria(criteria);
		}
		
		return actualRowsAffected;
	}
	
	public int insert(ChannelExt channelExt){
		return channelExtMapper.insert(channelExt);
	}
	
	public int updateByPrimaryKeySelective(ChannelExt channelExt){
		int actualRowsAffected = 0;
		
		int advertisingId = channelExt.getChannelId();

		ChannelExt _oldChannelExt = channelExtMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldChannelExt != null) {
			actualRowsAffected = channelExtMapper.updateByPrimaryKeySelective(channelExt);
		}
		
		return actualRowsAffected;
	}
	
	public int updateByPrimaryKey(ChannelExt channelExt){
		int actualRowsAffected = 0;
		
		int advertisingId = channelExt.getChannelId();

		ChannelExt _oldChannelExt = channelExtMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldChannelExt != null) {
			actualRowsAffected = channelExtMapper.updateByPrimaryKey(channelExt);
		}
		
		return actualRowsAffected;
	}
	
	public List<ChannelExt> selectByPage(ChannelExtCriteria criteria) {
		int totalResults = channelExtMapper.countByCriteria(criteria);
		Paging paging = criteria.getPaging();
		paging.setTotalResults(totalResults);
		
		return channelExtMapper.selectByPage(criteria,new RowBounds(paging.getFirstResult(),paging.getMaxResults()));
	}
	
	public int countByCriteria(ChannelExtCriteria criteria){
		return channelExtMapper.countByCriteria(criteria);
	}
	
	@Autowired
    private ChannelExtMapper channelExtMapper;
}
